// 产品相关API服务
import { http } from './http';

// 接口返回类型定义
interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
}

// 分页类型
interface Pagination {
  page: number;
  pageSize: number;
  total: number;
}

// 分页数据包装类型
interface PageResult<T> {
  pagination: Pagination;
  list: T[];
}

// 产品分类类型
interface ProductCategory {
  id: number;
  name: string;
  status: number;
  sort: number;
  parentId: number;
  [key: string]: any;
}

// 产品信息类型
interface Product {
  id: number;
  title: string;
  desc: string;
  price: number;
  image: string;
  category: number;
  [key: string]: any;
}

/**
 * 获取产品分类列表
 */
export const getProductCategoryList = () => {
  return http.get<ApiResponse<PageResult<ProductCategory>>>('/app/product/category/list', undefined, undefined, false);
};

/**
 * 获取产品列表
 * @param params 查询参数
 */
export const getProductList = (params?: {
  category?: number;
  keyword?: string;
  page?: number;
  pageSize?: number;
}) => {
  return http.get<ApiResponse<PageResult<Product>>>('/app/product/list', params, undefined, false);
};

/**
 * 获取产品详情
 * @param id 产品ID
 */
export const getProductDetail = (id: number) => {
  return http.get<ApiResponse<Product>>(`/app/product/${id}`, undefined, undefined, false);
}; 